<template>
  <!--是否行内表单-->
  <el-form :inline="inline" :model="form" label-width="100px" :rules="formRules" class="common-form" ref="commonForm">
    <!--标签显示名称-->
    <el-form-item v-for="(item,index) in formLabel" :key="index" :label="item.label" :prop="item.rule">
      <!--根据type来显示是什么标签 item.model:Code form[Code]:-->
      <el-input v-model="form[item.model]" :placeholder="item.readOnly==true?'':'请输入' + item.label"
                v-if="item.type==='input'&&item.hide!=='true'"
                :disabled="item.disabled" style="width: 300px" :readonly="item.readOnly"
                class="inputDeep"
      ></el-input>
      <el-input v-model="form[item.model]" :placeholder="item.readOnly==true?'':'请输入' + item.label"
                v-if="item.type==='textarea'&&item.hide!=='true'"
                :disabled="item.disabled" style="width: 300px" :readonly="item.readOnly"
                class="inputArea"
                type="textarea"
                :autosize="{ minRows: 2, maxRows: 10}"
      ></el-input>
      <lat-long :dmf="form.LaDFM" v-if="item.type==='latitude'" :disabled="item.disabled" ref="latitude" :is-lat="true"></lat-long>
      <lat-long :dmf="form.LongDFM" v-if="item.type==='longtitude'" :disabled="item.disabled" ref="longtitude"></lat-long>

      <el-select v-model="form[item.model]" placeholder="请选择" :disabled="item.disabled" v-if="item.type === 'select'"
                 style="width: 300px"
      >
        <!--如果是select或者checkbox 、Radio就还需要选项信息-->
        <el-option v-for="(item,index) in item.opts" :key="index" :label="item.label" :value="item.value"></el-option>
      </el-select>
      <el-switch v-model="form[item.model]" v-if="item.type === 'switch'"></el-switch>
      <el-date-picker
        v-model="form[item.model]"
        type="date"
        placeholder="选择日期"
        v-if="item.type === 'date'"
        value-format="yyyy-MM-dd"
      ></el-date-picker>
    </el-form-item>
    <el-form-item>
      <slot></slot>
    </el-form-item>
  </el-form>
</template>

<script>


import LatLong from '@/components/LatLong'

export default {
  components: { LatLong },
  // inline 属性可以让表单域变为行内的表单域
  // form 表单数据 formLabel 是标签数据
  props: {
    inline: Boolean,
    form: Object,
    formLabel: Array,
    formRules: Object
  }
}
</script>
<style lang="scss" scoped>
/* 利用穿透，设置input边框隐藏 */
.inputDeep > > > .el-input__inner {
  border: 0;
}

/* 如果你的 el-input type 设置成textarea ，就要用这个了 */
.inputDeep > > > .el-textarea__inner {
  border: 0;
  resize: none; /* 这个是去掉 textarea 下面拉伸的那个标志 */
}
</style>
